/**
 * Created by George on 2018/1/27.
 *
 */
define(['angular', 'util'], function (angular, util) {
    "use strict";
    // 将本控制器函数作为结果返回给router.js
    var duesCtrl = function ($scope, $http) {
        $scope.welcome_info = "会费管理";
        $scope.duesRecordDatas = [];

        function init() {
            initOrUpdateData();
        }

        function initOrUpdateData() {
            $http.get("/basketballfire/rest/dues/list").then(function (data, status) {
                console.log(data);
                $scope.duesRecordDatas = data.data.data;
            });
        }

        $scope.deleteDues = function (dues) {
            var msg = "您真的确定要删除吗？";
            if (!confirm(msg)) {
                return;
            }
            if (dues.activityId !== "") {
                alert("活动消费不能直接删除！");
                return;
            }

            $http.delete('/basketballfire/rest/dues?id=' + dues.id).then(function () {
                console.log("success!");
                alert("删除成功！");
                initOrUpdateData();
            }, function () {
                console.log("failed!");
                alert("删除失败！");
            });

        };

        init();
    };

    return duesCtrl;
});